﻿#include "mousekeyctrl.h"
#include "ui_mousekeyctrl.h"
#include "mouseacts.h"

MouseKeyCtrl::MouseKeyCtrl(QWidget *parent) :
    QWidget(parent),m_pTimer(NULL),
    ui(new Ui::MouseKeyCtrl)
{
    ui->setupUi(this);

    setWindowTitle(tr("鼠标模拟"));

    m_pTimer = new QTimer(this);
    m_pTimer->setInterval(500);
    connect(m_pTimer,SIGNAL(timeout()),this,SLOT(sltGetCursorPos()));
    m_pTimer->start();
}

MouseKeyCtrl::~MouseKeyCtrl()
{
    if(m_pTimer->isActive())
    {
        m_pTimer->stop();
    }
    if(m_pTimer != NULL)
    {
        delete m_pTimer;
        m_pTimer = NULL;
    }
    delete ui;
}

void MouseKeyCtrl::on_leftClickBtn_clicked()
{
    MouseActs::doPressAct(ui->spinBox_x->value(),ui->spinBox_y->value(),0,0,1);
}

void MouseKeyCtrl::on_leftDoubleClickBtn_clicked()
{
    MouseActs::doPressAct(ui->spinBox_x->value(),ui->spinBox_y->value(),0,0,2);
}

void MouseKeyCtrl::on_rightClickBtn_clicked()
{
    MouseActs::doPressAct(ui->spinBox_x->value(),ui->spinBox_y->value(),0,0,3);
}

void MouseKeyCtrl::on_rightDoubleClickBtn_clicked()
{
    MouseActs::doPressAct(ui->spinBox_x->value(),ui->spinBox_y->value(),0,0,4);
}

void MouseKeyCtrl::on_moveBtn_clicked()
{
    MouseActs::doPressAct(ui->spinBox_x->value(),ui->spinBox_y->value(),0,0,5);
}

void MouseKeyCtrl::on_dragBtn_clicked()
{
    MouseActs::doPressAct(ui->spinBox_x->value(),ui->spinBox_y->value(),
                          ui->dragSpinBox_x->value(),ui->dragSpinBox_y->value(),6);
}

void MouseKeyCtrl::sltGetCursorPos()
{
    QPoint mousePos = QCursor::pos();

    QString strPos;
    strPos.append("X=");
    strPos.append(QString::number(mousePos.x()));
    strPos.append(" Y=");
    strPos.append(QString::number(mousePos.y()));
    ui->label_pos->setText(strPos);

    QApplication::processEvents();
}
